package mate_preference

import (
	"context"

	"algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/application/dto"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/svc"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BatchSyncMatePreferenceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBatchSyncMatePreferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BatchSyncMatePreferenceLogic {
	return &BatchSyncMatePreferenceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BatchSyncMatePreferenceLogic) BatchSyncMatePreference(req *types.BatchSyncMatePreferenceRequest) (resp *types.BatchSyncMatePreferenceResponse, err error) {
	syncReason, err := l.svcCtx.MatePreferenceService.BatchAddMatePreference(l.ctx, tools.Cast(req.MatePreferenceList, transMatePreferenceCommand))
	if err != nil {
		return nil, err
	}

	resp = &types.BatchSyncMatePreferenceResponse{
		Data: types.BatchSyncMatePreferenceData{
			SyncMatePreferenceResult: types.SyncMatePreferenceResult{
				SuccessList: syncReason.SuccessList,
				FailedList: tools.Cast(syncReason.FailedList, func(r dto.FailedReason) types.FailedReason {
					return types.FailedReason{
						UserNum: r.UserNum,
						Reason:  r.Reason,
					}
				}),
			},
		},
	}

	return
}
